<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/11/11
 * Time: 13:52
 */

namespace HiCommon\Model;

use App\User;

class StoreOrderRefund extends Base
{

    protected $table = 'store_order_refund';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    /**
     * 关联店铺
     */
    public function shop_name()
    {
        return $this->belongsTo(Shop::class, 'shop_id')->select(['id', 'name', 'phone']);
    }

    /**
     *  关联商城订单
     *
     **/
    public function store_order()
    {
        return $this->belongsTo(StoreOrder::class, 'store_order_id')
            ->select(['id', 'pay_type', 'shop_id', 'order_type', 'order_no', 'status', 'pay_status', 'goods_num', 'pay_amount', 'order_amount', 'coupon_price', 'created_at','delivery_price']);
    }

    /**
     * 关联退单关系表
     */
    public function get_order_refund_goods()
    {
        return $this->hasMany(StoreOrderRefundGoods::class, 'store_order_refund_id', 'id')
            ->with(['order_goods'])
            ->select(['id', 'store_order_refund_id', 'store_order_goods_id']);
    }

    /**
     *  关联订单商品(售后订单用)
     *
     **/
    public function get_refund_price()
    {
        return $this->hasMany(StoreOrderRefundGoods::class, 'store_order_refund_id', 'id')
            ->with(['get_order_goods'])
            ->select(['id', 'store_order_refund_id', 'store_order_goods_id']);
    }

    /**
     *  关联用户
     *
     **/
    public function get_user()
    {
        return $this->hasOne(Users::class, 'id', 'user_id')
            ->select(['id', 'username', 'nickname', 'phone']);
    }



    /**
     *  关联订单商品
     *
     **/
   /* public function order_goods()
    {
        return $this->hasMany(StoreOrderGoods::class, 'store_order_refund_id', 'id')
            ->with(['goods', 'goods_product' => function ($query) {
                $query->with(['specs', 'goods_info']);
            }]);
    }*/










    /**
     *  退货原因
     *
     **/
    public function refund_reason_id()
    {
        return $this->hasOne(CancelReason::class, 'id', 'refund_reason_id')
            ->select(['id', 'reason', 'type']);
    }

    /**
     *  关联快递公司
     *
     **/
    public function getExpress()
    {
        return $this->hasOne(Express::class, 'id', 'express_id')->select(['id', 'name', 'type']);
    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getImgUrlAttribute($value)
    {
        $arr_data = [
            'src' => $value,
            'full_src' => oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = [
            'created_at' => ymd_friendly_date($s_created_at),
        ];

        return $arr_data;
    }


}